package com.ai.emall.api.productmanage.impl;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import com.ai.emall.business.interfaces.IProductManageQuerySV;
import com.ai.emall.utils.constants.SysExceptCodeConstants;
import com.ai.emall.utils.exception.BusinessException;
import com.ai.gcf.api.base.vo.PageInfo;
import com.ai.gcf.api.base.vo.ResponseHeader;
import com.ai.gcf.api.emall.productmanage.interfaces.IProductManageQueyDubboSV;
import com.ai.gcf.api.emall.productmanage.param.ProductInfo;
import com.ai.gcf.api.emall.productmanage.param.ProductPageQueryByModuleIdRequest;
import com.ai.gcf.api.emall.productmanage.param.ProductPageQueryByModuleIdResponse;
import com.ai.gcf.api.emall.productmanage.param.ProductQueryByModuleIdRequest;
import com.ai.gcf.api.emall.productmanage.param.ProductQueryByModuleIdResponse;
import com.ai.gcf.api.emall.productmanage.param.ProductQueryByProductIdRequest;
import com.ai.gcf.api.emall.productmanage.param.ProductQueryByProductIdResponse;

/** 
 * 产品查询实现
 * @author zhaowg3
 * @Date 2016年12月20日
 */

public class ProductManageQueyDubboSVImpl implements IProductManageQueyDubboSV {
	@Autowired
	private IProductManageQuerySV iProductManageQuerySV;
	@Override
	public ProductQueryByModuleIdResponse productQueryByModuleId(ProductQueryByModuleIdRequest request) throws Exception {
		if(request == null)
			throw new BusinessException(SysExceptCodeConstants.Special.PARAM_IS_NULL, "请求参数为空");
		if(StringUtils.isBlank(request.getModuleId()))
			throw new BusinessException(SysExceptCodeConstants.Special.PARAM_IS_NULL, "请求参数moduleId为空",true);
		List<ProductInfo> productInfos = iProductManageQuerySV.productQueryByModuleId(request.getModuleId(), request.getStatus());
		ProductQueryByModuleIdResponse response = new ProductQueryByModuleIdResponse();
		response.setProductInfos(productInfos);
		response.setResponseHeader(new ResponseHeader(SysExceptCodeConstants.Special.SUCCESS, "成功"));
		return response;
	}

	@Override
	public ProductQueryByProductIdResponse productQueryByProductId(ProductQueryByProductIdRequest request) throws Exception {
		if(request == null)
			throw new BusinessException(SysExceptCodeConstants.Special.PARAM_IS_NULL, "请求参数为空");
		if(request.getProductId()==null)
			throw new BusinessException(SysExceptCodeConstants.Special.PARAM_IS_NULL, "请求参数产品ID为空",true);
		ProductInfo productInfo = iProductManageQuerySV.productQueryByProductId(request.getProductId());
		ProductQueryByProductIdResponse response = new ProductQueryByProductIdResponse();
		response.setProductInfo(productInfo);
		response.setResponseHeader(new ResponseHeader(SysExceptCodeConstants.Special.SUCCESS, "成功"));
		return response;
	}

	@Override
	public ProductPageQueryByModuleIdResponse productPageQueryByModuleId(ProductPageQueryByModuleIdRequest request)
			throws Exception {
		if(request == null)
			throw new BusinessException(SysExceptCodeConstants.Special.PARAM_IS_NULL, "请求参数为空",true);
		if(StringUtils.isBlank(request.getModuleId()))
			throw new BusinessException(SysExceptCodeConstants.Special.PARAM_IS_NULL, "请求参数moduleId为空",true);
		if(StringUtils.isBlank(request.getStatus()))
			throw new BusinessException(SysExceptCodeConstants.Special.PARAM_IS_NULL, "请求参数Status为空",true);
		if(request.getPageNo()==null)
			throw new BusinessException(SysExceptCodeConstants.Special.PARAM_IS_NULL, "请求参数PageNo为空",true);
		if(request.getPageSize()==null)
			throw new BusinessException(SysExceptCodeConstants.Special.PARAM_IS_NULL, "请求参数PageSize为空",true);
		PageInfo<ProductInfo> productInfos = iProductManageQuerySV.productQueryByModuleId(request.getModuleId(), request.getStatus(),request.getPageNo(),request.getPageSize());
		ProductPageQueryByModuleIdResponse response = new ProductPageQueryByModuleIdResponse();
		response.setProductInfos(productInfos);
		response.setResponseHeader(new ResponseHeader(SysExceptCodeConstants.Special.SUCCESS, "成功"));
		return response;
	}

}
